From 7af0e8c1e10afbf6f3d652c4851a1ccdb854b709 Mon Sep 17 00:00:00 2001 From: Ell Date: Wed, 30 May 2018 06:01:27 -0400 Subject: [PATCH] babl-palette: warn when trying to create a 0-color palette In babl_palette_set_palette(), fall back to the default palette, and log a warning, when trying to create a palette with < 1 colors. --- babl/babl-palette.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/babl/babl-palette.c b/babl/babl-palette.c index 5b19c0a..278c854 100644 --- a/babl/babl-palette.c +++ b/babl/babl-palette.c @@ -244,6 +244,8 @@ static BablPalette *make_pal (const Babl *format, const void *data, int count) BablPalette *pal = NULL; int bpp = babl_format_get_bytes_per_pixel (format); + babl_assert (count > 0); + pal = babl_malloc (sizeof (BablPalette)); pal->count = count; pal->format = format; @@ -870,7 +872,16 @@ babl_palette_set_palette (const Babl *babl, { BablPalette **palptr = babl_get_user_data (babl); babl_palette_reset (babl); - *palptr = make_pal (format, data, count); + if (count > 0) + { + *palptr = make_pal (format, data, count); + } + else + { + babl_log ("attempt to create a palette with %d colors. " + "using default palette instead.", + count); + } } void -- 2.30.2